<template>
	<view class="current-activity">
		<view class="current-activity-header">
			<view class="activity-tag activity-tag-seckill">秒杀</view>
			<text class="current-activity-title">{{ activityName }}</text>
		</view>
		
		<view class="activity-detail">
			<view class="seckill-info">
				<text class="seckill-progress">已抢{{ progressPercent }}%</text>
				<progress :percent="progressPercent" stroke-width="4" activeColor="#ff9500" class="seckill-progress-bar" />
			</view>
			<view class="activity-countdown">
				<text class="countdown-label">距结束</text>
				<text class="countdown-time">{{ countdownTime }}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, computed, onMounted, onUnmounted } from 'vue';
	
	const props = defineProps({
		activityType: {
			type: String,
			default: 'seckill'
		},
		currentActivity: {
			type: Object,
			default: () => null
		}
	});
	
	// 秒杀活动名称
	const activityName = computed(() => {
		if (props.currentActivity && props.currentActivity.name) {
			return props.currentActivity.name;
		}
		return '限时秒杀，低至7折';
	});
	
	// 秒杀进度
	const progressPercent = ref(75);
	
	// 倒计时
	const countdownTime = ref('23:59:59');
	let timer = null;
	
	// 模拟倒计时
	const startCountdown = () => {
		// 实际项目中应该根据活动结束时间计算倒计时
		// 这里仅作为示例
		let hours = 23;
		let minutes = 59;
		let seconds = 59;
		
		timer = setInterval(() => {
			seconds--;
			if (seconds < 0) {
				seconds = 59;
				minutes--;
				if (minutes < 0) {
					minutes = 59;
					hours--;
					if (hours < 0) {
						clearInterval(timer);
						return;
					}
				}
			}
			countdownTime.value = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
		}, 1000);
	};
	
	onMounted(() => {
		startCountdown();
		
		// 模拟进度变化
		const progressTimer = setInterval(() => {
			if (progressPercent.value < 100) {
				progressPercent.value += 1;
			} else {
				clearInterval(progressTimer);
			}
		}, 5000);
	});
	
	onUnmounted(() => {
		if (timer) {
			clearInterval(timer);
		}
	});
</script>

<style lang="scss" scoped>
.current-activity {
	margin-bottom: 15px;
	padding-bottom: 15px;
	border-bottom: 1px dashed #eee;

	.current-activity-header {
		display: flex;
		align-items: center;
		margin-bottom: 10px;

		.activity-tag {
			padding: 2px 6px;
			border-radius: 3px;
			font-size: 11px;
			color: white;
			margin-right: 8px;
			
			&.activity-tag-seckill {
				background-color: #ff9500;
			}
		}

		.current-activity-title {
			font-size: 14px;
			font-weight: bold;
			color: #333;
		}
	}

	.activity-detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 10px;

		.activity-countdown {
			display: flex;
			align-items: center;

			.countdown-label {
				font-size: 12px;
				color: #666;
				margin-right: 5px;
			}

			.countdown-time {
				font-size: 14px;
				color: #ff3b30;
				font-weight: bold;
			}
		}
	}

	.seckill-info {
		.seckill-progress {
			font-size: 13px;
			color: #333;
			margin-bottom: 5px;
		}

		.seckill-progress-bar {
			width: 120px;
			height: 6px;
			margin-top: 5px;
		}
	}
}
</style>